package cn.tedu.map;

import java.util.*;

/**本类用于回顾Map*/
public class TestMap {
    public static void main(String[] args) {
       Map<String, Integer> map = new HashMap<>();
       map.put("张三",3);
       map.put("李四",4);
       map.put("王五",5);
//       map.put("赵六六",null);//可以
//        map.put("null",6);//可以
        System.out.println(map);
        /**如果map中没有存过"赵六"，那么根据key获取的value值一定是null*/
        System.out.println(map.get("赵六"));

        System.out.println(map.containsKey("张三"));
        System.out.println(map.containsValue(5));
        System.out.println(map.isEmpty());
        System.out.println(map.get("李四"));
        System.out.println(map.remove("张三"));

        Collection<Integer> values = map.values();
        System.out.println(values);

        System.out.println(map.size());

        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()){
            String key = it.next();
            Integer value = map.get(key);
            System.out.println(key+value);
        }

        Set<Map.Entry<String, Integer>> set2 = map.entrySet();
        Iterator<Map.Entry<String, Integer>> it2 = set2.iterator();
        while (it2.hasNext()){
            Map.Entry<String, Integer> entry = it2.next();
            System.out.println(entry);
        }

    }
}
